package com.highper.gateway.controller;

import com.highper.common.entity.response.HighperResponse;
import com.highper.common.entity.vo.LoginVo;
import com.highper.gateway.service.IAuthService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

/**
 * @Author ZhangGJ
 * @Date 2022/01/24 15:53
 */
@Validated
@RestController
@RequestMapping("auth")
public class AuthController {

    private final IAuthService authService;

    @Autowired
    public AuthController(IAuthService authService) {
        this.authService = authService;
    }

    @PostMapping("login")
    public HighperResponse login(@RequestBody @Valid LoginVo loginVo) {
        return HighperResponse.data(authService.login(loginVo));
    }

    @GetMapping("logout")
    public HighperResponse logout() {
        return HighperResponse.resultWebFlux(authService.logout());
    }

    @GetMapping("login/status")
    public HighperResponse loginStatus() {
        return HighperResponse.data(authService.loginStatus());
    }

    @GetMapping("token/info")
    public HighperResponse tokenInfo() {
        return HighperResponse.data(authService.tokenInfo());
    }
}
